package php;

import com.google.common.collect.Lists;
import utils.VirtualFolder;
import utils.files.File;
import utils.titles.Title;
import php.code.Sequence;
import php.code.instructions.Instruction;

public class PhpFile extends File {

    private Sequence uses;

    public PhpFile(VirtualFolder folder, Title title, Object... elements) {
        super(folder, title.toUpperCamel(), "php", Lists.asList("<?php", elements).toArray());
    }

    public PhpFile(VirtualFolder folder, String lowerCamel, Object... elements) {
        super(folder, lowerCamel, "php", Lists.asList("<?php", elements).toArray());
    }

    public void use(String type) {
        if (uses == null) {
            uses = new Sequence();
            add(1, uses);
        }

        uses.add(new Use(type));
    }

    private class Use extends Instruction{
        private String type;

        public Use(String type) {
            super(false);
            this.type = type;
        }

        @Override
        protected String getCode() {
            return "use " + type + ";";
        }
    }
}
